import json

from api.base_service import BaseService


class OrderSettingService(BaseService):
    def add(self, data: list):
        """
        添加预约设置
        :param data: java.util.List
        :return: str
        """
        resp = self.dubbo_client.invoke("OrderSettingService", "add", data)
        if resp == "null":
            return True
        return False

    def get_order_setting_by_month(self, date: str):
        """
        按月统计预约设置信息
        :param date: String
        :return: java.util.List
        """
        resp = self.dubbo_client.invoke("OrderSettingService", "getOrderSettingByMonth", date)
        if resp == "Failed":
            return None
        return json.loads(resp)

    def edit_number_by_date(self, data):
        """
        根据日期修改预约设置数量
        :param data: OrderSetting
        :return: null
        """
        data["class"] = "com.itheima.pojo.OrderSetting"
        resp = self.dubbo_client.invoke("OrderSettingService", "editNumberByDate", data)
        if resp == "null":
            return True
        return False


if __name__ == '__main__':
    print(OrderSettingService().add([{"orderDate": "2025-04-27 14:22:22", "number": 527}]))
    print(OrderSettingService().get_order_setting_by_month("2025-04"))
    print(OrderSettingService().edit_number_by_date({"orderDate": "2025-04-25 14:22:22", "number": 842}))
